package net.micode.notes.ui;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R; // 导入资源类 R，用于引用资源文件
public class PasswordView extends Dialog {
    private EditText mPasswordInput;
    private Button mConfirmButton;
    private Button mCancelButton;
    private Context mContext;
    private OnPasswordConfirmedListener mListener;

    public interface OnPasswordConfirmedListener {
        void onPasswordConfirmed(String password);
        void onCancel();
    }

    public PasswordView(Context context, OnPasswordConfirmedListener listener) {
        super(context);
        mContext = context;
        mListener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.note_encryption); // 确保布局文件存在

        mPasswordInput = findViewById(R.id.et_password);
        mConfirmButton = findViewById(R.id.btn_confirm);
        mCancelButton = findViewById(R.id.btn_cancel);

        mConfirmButton.setOnClickListener(v -> {
            String password = mPasswordInput.getText().toString();
            if (!TextUtils.isEmpty(password)) {
                mListener.onPasswordConfirmed(password);
                dismiss();
            } else {
                Toast.makeText(mContext, R.string.password_empty, Toast.LENGTH_SHORT).show();
            }
        });

        mCancelButton.setOnClickListener(v -> {
            mListener.onCancel();
            dismiss();
        });
    }
}